home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / source / blt / setdi8.asm < prev    next >
Encoding:
Assembly Source File  |  1993-09-03  |  10.4 KB  |  379 lines

  1. page    ,132
  2. ;----------------------------Module-Header------------------------------;
  3. ; Module Name: SETDI8.ASM
  4. ;
  5. ; move bits from one DIB format into another. doing color conversion if
  6. ; needed.
  7. ;
  8. ;   convert_8_8
  9. ;   convert_16_8
  10. ;   convert_24_8
  11. ;   convert_32_8
  12. ;   copy_8_8
  13. ;   dither_8_8
  14. ;
  15. ; NOTES:
  16. ;
  17. ;  dither needs to work!
  18. ;
  19. ;  AUTHOR: ToddLa (Todd Laney) Microsoft
  20. ;
  21. ;-----------------------------------------------------------------------;
  22. ?PLM=1
  23. ?WIN=0
  24.     .xlist
  25.         include cmacro32.inc
  26.         include windows.inc
  27.         .list
  28.  
  29. sBegin  Data
  30. sEnd    Data
  31.  
  32. ifndef SEGNAME
  33.     SEGNAME equ <_TEXT32>
  34. endif
  35.  
  36. createSeg %SEGNAME, CodeSeg, word, public, CODE
  37.  
  38. sBegin  CodeSeg
  39.         .386
  40.         assumes cs,CodeSeg
  41.         assumes ds,nothing
  42.         assumes es,nothing
  43.  
  44. ;--------------------------------------------------------------------------;
  45. ;--------------------------------------------------------------------------;
  46.  
  47. nxtscan macro reg, next_scan, fill_bytes
  48. ifb <fill_bytes>
  49.         add     e®,next_scan
  50. else
  51.         mov     eax,e®
  52.         add     e®,next_scan
  53.         cmp     ax,reg
  54.         sbb     eax,eax
  55.         and     eax,fill_bytes
  56.         add     e®,eax
  57. endif
  58.         endm
  59.  
  60. if 0
  61. ;--------------------------------------------------------------------------;
  62. ;
  63. ;   convert_8_8
  64. ;
  65. ;--------------------------------------------------------------------------;
  66.         assumes ds,nothing
  67.         assumes es,nothing        
  68.  
  69. cProc   convert_8_8,<FAR,PUBLIC,PASCAL>,<esi,edi,ds>
  70.         ParmD   dst_ptr             ; --> dst.
  71.         ParmD   dst_offset          ; offset to start at
  72.         ParmD   dst_next_scan       ; dst_next_scan.
  73.         ParmD   src_ptr             ; --> src.
  74.         ParmD   src_offset          ; offset to start at
  75.         ParmD   src_next_scan       ; dst_next_scan.
  76.         ParmD   pel_count           ; pixel count.
  77.         ParmD   scan_count          ; scan count.
  78.         ParmD   xlat_table          ; pixel convert table.
  79. cBegin
  80.         xor     esi,esi
  81.         xor     edi,edi
  82.         xor     ebx,ebx
  83.         lfs     si,src_ptr
  84.         les     di,dst_ptr
  85.         lds     bx,xlat_table
  86.  
  87.         add     esi,src_offset
  88.         add     edi,dst_offset
  89.  
  90.         mov     eax,pel_count
  91.         sub     src_next_scan,eax
  92.         sub     dst_next_scan,eax
  93.  
  94.     mov    edx,pel_count
  95.     xor    ebx,ebx
  96. align 4
  97. convert_8_8_start:
  98.     mov    ecx,edx ;pel_count
  99.     shr    ecx,2
  100.         jz      short convert_8_8_ack
  101. align 4
  102. convert_8_8_loop:
  103.         mov     eax,fs:[esi]        ; grab 4 pixels
  104.  
  105.     mov    bl,al            ; get pel
  106.     mov    al,[ebx]        ; translate pel
  107.     mov    bl,ah            ; get pel
  108.     mov    ah,[ebx]        ; translate pel
  109.  
  110.         rol     eax,16
  111.  
  112.     mov    bl,al            ; get pel
  113.     mov    al,[ebx]        ; translate pel
  114.     mov    bl,ah            ; get pel
  115.     mov    ah,[ebx]        ; translate pel
  116.  
  117.         rol     eax,16
  118.         mov     es:[edi],eax        ; store four
  119.  
  120.         add     esi,4
  121.         add     edi,4
  122.     dec    ecx
  123.     jnz    short convert_8_8_loop
  124.  
  125. convert_8_8_ack:
  126.     mov    ecx,edx ;pel_count
  127.     and    ecx,3
  128.     jnz    short convert_8_8_odd
  129.  
  130. convert_8_8_next:
  131.     nxtscan si,src_next_scan
  132.         nxtscan di,dst_next_scan
  133.  
  134.         dec     scan_count
  135.         jnz     short convert_8_8_start
  136. cEnd
  137.  
  138. convert_8_8_odd:
  139. @@:    mov    bl,fs:[esi]
  140.     mov    bl,[ebx]
  141.         mov     es:[edi],bl
  142.         inc     esi
  143.         inc     edi
  144.     dec    ecx
  145.     jnz    short convert_8_8_odd
  146.         jz      short convert_8_8_next
  147.  
  148. endif
  149.  
  150. ;--------------------------------------------------------------------------;
  151. ;
  152. ;   copy_8_8
  153. ;
  154. ;--------------------------------------------------------------------------;
  155.         assumes ds,nothing
  156.         assumes es,nothing        
  157.  
  158. cProc   copy_8_8,<FAR,PUBLIC,PASCAL>,<esi,edi,ds>
  159.         ParmD   dst_ptr             ; --> dst.
  160.         ParmD   dst_offset          ; offset to start at
  161.         ParmD   dst_next_scan       ; dst_next_scan.
  162.         ParmD   src_ptr             ; --> src.
  163.         ParmD   src_offset          ; offset to start at
  164.         ParmD   src_next_scan       ; dst_next_scan.
  165.         ParmD   pel_count               ; pixel count.
  166.         ParmD   scan_count              ; scan count.
  167.         ParmD   xlat_table          ; pixel convert table.
  168. cBegin
  169.         xor     esi,esi
  170.         xor     edi,edi
  171.         lds     si,src_ptr
  172.         les     di,dst_ptr
  173.  
  174.         add     esi,src_offset
  175.         add     edi,dst_offset
  176.  
  177.         mov     eax,pel_count
  178.         sub     src_next_scan,eax
  179.         sub     dst_next_scan,eax
  180.  
  181.         mov     eax,src_next_scan
  182.         or      eax,dst_next_scan
  183.     jz    short copy_8_8_all
  184.  
  185. copy_8_8_rect:
  186.         mov     ebx,pel_count
  187.         mov     edx,ebx
  188.  
  189.         shr     ebx,2
  190.         and     edx,3
  191. align 4
  192. copy_8_8_start:
  193.         mov     ecx,ebx
  194.         rep     movs dword ptr es:[edi], dword ptr ds:[esi]
  195.         mov     ecx,edx
  196.         rep     movs byte ptr es:[edi], byte ptr ds:[esi]
  197.     nxtscan si,src_next_scan
  198.         nxtscan di,dst_next_scan
  199.         dec     scan_count
  200.         jnz     short copy_8_8_start
  201. copy_8_8_exit:
  202. cEnd
  203.  
  204. copy_8_8_all:
  205.         mov     eax,pel_count
  206.         mul     scan_count
  207.         mov     ecx,eax
  208.         shr     ecx,2
  209.         rep     movs dword ptr es:[edi], dword ptr ds:[esi]
  210.         mov     ecx,eax
  211.         and     ecx,3
  212.         rep     movs byte ptr es:[edi], byte ptr ds:[esi]
  213.         jmp     short copy_8_8_exit
  214.  
  215. ;--------------------------------------------------------------------------;
  216. ;
  217. ;   dither_8_8
  218. ;
  219. ;       pel = xlat[y&7][pel][x&7]
  220. ;
  221. ;--------------------------------------------------------------------------;
  222.         assumes ds,nothing
  223.         assumes es,nothing        
  224.  
  225. cProc   dither_8_8,<FAR,PUBLIC,PASCAL>,<esi,edi,ds>
  226.         ParmD   dst_ptr             ; --> dst.
  227.         ParmD   dst_offset          ; offset to start at
  228.         ParmD   dst_next_scan       ; dst_next_scan.
  229.         ParmD   src_ptr             ; --> src.
  230.         ParmD   src_offset          ; offset to start at
  231.         ParmD   src_next_scan       ; dst_next_scan.
  232.         ParmD   pel_count               ; pixel count.
  233.         ParmD   scan_count              ; scan count.
  234.         ParmD   xlat_table          ; pixel convert table.
  235. cBegin
  236.         xor     esi,esi
  237.         xor     edi,edi
  238.         xor     ebx,ebx
  239.         lfs     si,src_ptr
  240.         les     di,dst_ptr
  241.         lds     bx,xlat_table
  242.  
  243. ifdef DEBUG
  244.         or      ebx,ebx
  245.         jz      @f
  246.         int 3
  247. @@:
  248. endif
  249.         add     esi,src_offset
  250.         add     edi,dst_offset
  251.  
  252.         and     pel_count,not 3     ;;!!! round down to multiple of 4
  253.  
  254.         mov     eax,pel_count
  255.         sub     src_next_scan,eax
  256.         sub     dst_next_scan,eax
  257.  
  258.         shr     eax,2
  259.         jz      short dither_8_8_exit
  260.         mov     pel_count,eax
  261.  
  262.         xor     edx,edx             ; y = 0
  263. align 4
  264. dither_8_8_start:
  265.         mov     ecx,pel_count
  266.         xor     ebx,ebx             ; x = 0
  267. align 4
  268. dither_8_8_loop:
  269.         mov     eax,fs:[esi]        ; grab 4 pixels
  270.  
  271.         mov     dl,al               ; get pel
  272.         mov     al,[edx*8+ebx]      ; get dithered version of the pixel.
  273.         inc     bl
  274.  
  275.         mov     dl,ah               ; get pel
  276.         mov     ah,[edx*8+ebx]      ; get dithered version of the pixel.
  277.         inc     bl
  278.  
  279.         rol     eax,16
  280.  
  281.         mov     dl,al               ; get pel
  282.         mov     al,[edx*8+ebx]      ; get dithered version of the pixel.
  283.         inc     bl
  284.  
  285.         mov     dl,ah               ; get pel
  286.         mov     ah,[edx*8+ebx]      ; get dithered version of the pixel.
  287.         inc     bl
  288.         and     bl,7
  289.  
  290.         rol     eax,16
  291.         mov     es:[edi],eax
  292.  
  293.         add     esi,4
  294.         add     edi,4
  295.         dec     ecx
  296.         jnz     short dither_8_8_loop
  297.  
  298. dither_8_8_next:
  299.         inc     dh
  300.         and     dh,7
  301.     nxtscan si,src_next_scan
  302.         nxtscan di,dst_next_scan
  303.  
  304.         dec     scan_count
  305.         jnz     short dither_8_8_start
  306.  
  307. dither_8_8_exit:
  308. cEnd
  309.  
  310. ;--------------------------------------------------------------------------;
  311. ;
  312. ;   convert_16_8
  313. ;
  314. ;--------------------------------------------------------------------------;
  315.         assumes ds,nothing
  316.         assumes es,nothing        
  317.  
  318. cProc   convert_16_8,<FAR,PUBLIC,PASCAL>,<esi,edi,ds>
  319.         ParmD   dst_ptr             ; --> dst.
  320.         ParmD   dst_offset          ; offset to start at
  321.         ParmD   dst_next_scan       ; dst_next_scan.
  322.         ParmD   src_ptr             ; --> src.
  323.         ParmD   src_offset          ; offset to start at
  324.         ParmD   src_next_scan       ; dst_next_scan.
  325.     ParmD    pel_count        ; pixel count.
  326.     ParmD    scan_count        ; scan count.
  327.         ParmD   xlat_table          ; pixel convert table.
  328. cBegin
  329.     ; we need dither code here!
  330. cEnd
  331.  
  332. ;--------------------------------------------------------------------------;
  333. ;
  334. ;   convert_24_8
  335. ;
  336. ;--------------------------------------------------------------------------;
  337.         assumes ds,nothing
  338.         assumes es,nothing        
  339.  
  340. cProc   convert_24_8,<FAR,PUBLIC,PASCAL>,<esi,edi,ds>
  341.         ParmD   dst_ptr             ; --> dst.
  342.         ParmD   dst_offset          ; offset to start at
  343.         ParmD   dst_next_scan       ; dst_next_scan.
  344.         ParmD   src_ptr             ; --> src.
  345.         ParmD   src_offset          ; offset to start at
  346.         ParmD   src_next_scan       ; dst_next_scan.
  347.         ParmD   pel_count               ; pixel count.
  348.         ParmD   scan_count              ; scan count.
  349.         ParmD   xlat_table          ; pixel convert table.
  350. cBegin
  351.     ; we need dither code here!
  352. cEnd
  353.  
  354. ;--------------------------------------------------------------------------;
  355. ;
  356. ;   convert_32_8
  357. ;
  358. ;--------------------------------------------------------------------------;
  359.         assumes ds,nothing
  360.         assumes es,nothing        
  361.  
  362. cProc   convert_32_8,<FAR,PUBLIC,PASCAL>,<esi,edi,ds>
  363.         ParmD   dst_ptr             ; --> dst.
  364.         ParmD   dst_offset          ; offset to start at
  365.         ParmD   dst_next_scan       ; dst_next_scan.
  366.         ParmD   src_ptr             ; --> src.
  367.         ParmD   src_offset          ; offset to start at
  368.         ParmD   src_next_scan       ; dst_next_scan.
  369.         ParmD   pel_count               ; pixel count.
  370.         ParmD   scan_count              ; scan count.
  371.         ParmD   xlat_table          ; pixel convert table.
  372. cBegin
  373.     ; we need dither code here!
  374. cEnd
  375.  
  376. sEnd    CodeSeg
  377.  
  378. end
  379.